home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Plurals / mp_xnet.m < prev    next >
Text File  |  1992-07-15  |  10KB  |  349 lines

  1. /*
  2.  *    Paralation Lisp
  3.  *
  4.  *    Author:    S.C.Merrall
  5.  *
  6.  *    File:    mp_xnet.m
  7.  *
  8.  *    Contents:    mp_xnet
  9.  *            get
  10.  *            edge
  11.  *
  12.  *    Description:    The functions in this file were created
  13.  *                      explicitly to make handling wrapped nearest
  14.  *                      neighbour communication easier. The most
  15.  *                      important difference is that teh functions do
  16.  *                      not work on single offsets but a list of
  17.  *                      offsets which is transferred between the
  18.  *                      scratch spaces of the host and ACU
  19.  *
  20.  *    Change History:
  21.  *
  22.  *    Date   Name Comment
  23.  *    -------- ---- -------
  24.  *    05:06:92 SCM  Created
  25.  *    17:06:92 SCM  Added edge, which is a context stack modifier
  26.  */
  27.  
  28. #include <mpl.h>
  29. #include <stdio.h>
  30. #include "proc_pair.h"
  31.  
  32. #include "mp_eubang.h"  /*  Includes constant.h too */
  33. #include "mp_object.h"
  34. #include "mp_debug_off.h"
  35. #include "mp_mem_mgmt.h"
  36. #include "mp_gc.h"
  37. #include "mp_utils.h"
  38.  
  39. /*----------------------------------------------------------------------------*
  40.  * Function   : get
  41.  *
  42.  * Parameters : MPC:                            The context of the plural
  43.  *              MP_PluralHeap MPPH_data:    The plural to be shifted in 
  44.  *                        the given direction
  45.  *        int direction:            The direction to shift in
  46.  *
  47.  * Description: Encodes the lisp objects into the scratch space shifts them
  48.  *        in the specified direction builds copies in the pes and 
  49.  *        the value of the argument is now the shifted structures
  50.  *
  51.  * Result     : int FAIL/SUCCESS
  52.  *---------------------------------------------------------------------------*/
  53.  
  54. #ifdef __STDC__
  55.  
  56. int get( object MPC, MP_PluralHeap MPPH_data, int direction )
  57.  
  58. #else
  59.  
  60. int get( MPC, MPPH_data, direction )
  61.  
  62. object MPC;
  63. MP_PluralHeap MPPH_data;
  64. int direction;
  65.  
  66. #endif
  67.  
  68. {
  69.   int delta_x = 0;
  70.   int delta_y = 0;
  71.   plural int other_edge;
  72.   MP_PluralHeap MPPH_pluralHeap;
  73.   plural int index;
  74. DBG_CALL("get");
  75. DBG_ARGS(fprintf(dbg,"MPC=%x,",MPC);DBG_PARG("MPPH_data","%x ",MPPH_data);fprintf(dbg,"direction=%d",direction));
  76.   
  77.  
  78.   OM_with_context(MPC) {
  79.  
  80.     scratch[0] = 1;
  81.     encode(MPPH_data);
  82.  
  83.     switch (direction) {
  84.  
  85.      case MP_NORTH: delta_y = -1; break;
  86.      case MP_SOUTH: delta_y =  1; break;
  87.      case MP_WEST : delta_x =  2; break;
  88.      case MP_EAST : delta_x = -2; break;
  89.  
  90.     }
  91. DEBUG(fprintf(dbg,"delta_x=%d,delta_y=%d",delta_x,delta_y));
  92.  
  93.     pp_xsend(delta_y,delta_x, (plural char *plural) scratch,
  94.          (plural char *plural) scratch, SCRATCH_MEMORY_SIZE);
  95.  
  96.     if ((((direction == MP_NORTH) || (direction == MP_SOUTH)) && 
  97.      (OA_height(MPC) == PP_nyproc)) ||
  98.     (((direction == MP_WEST) || (direction == MP_EAST)) &&
  99.      (OA_width(MPC) == PP_nxproc))) {
  100.     }
  101.     else if (((direction==MP_NORTH) && OM_top_edge(MPC)) ||
  102.          ((direction==MP_SOUTH) && OM_bottom_edge(MPC)) ||
  103.          ((direction==MP_WEST) &&  OM_left_edge(MPC)) ||
  104.          ((direction==MP_EAST) && OM_right_edge(MPC))) {
  105.       
  106. DEBUG(DBG_PARG("iproc"," %d",iproc));
  107.       other_edge = ((iyproc - (delta_y * OA_height(MPC))) * nxproc) +
  108.         ((ixproc + (OA_width(MPC) * delta_x)) % nxproc);
  109.  
  110.       other_edge = (other_edge + nproc ) % nproc;
  111. DEBUG(DBG_PARG("other_edge"," %d",other_edge));
  112.     
  113.       ss_rfetch(other_edge,scratch,scratch,SCRATCH_MEMORY_SIZE);
  114.     }
  115.     
  116.     index = 1;
  117.     if (decode(MPPH_data, &index)== FAIL) {
  118.       
  119. DBG_FAIL(fprintf(dbg,"FAIL: decode stage of get failed"));
  120.       mp_error = MP_DECODE_IN_GET_FAILED;
  121.       return FAIL;
  122.     }
  123.   } /* matches POM_with_conttext(MPC) */
  124.  
  125. DBG_EXIT(fprintf(dbg,"SUCCESS"));
  126.   return SUCCESS;
  127. }
  128.  
  129. /*----------------------------------------------------------------------------*
  130.  * Function   : mp_xnet
  131.  *
  132.  * Parameters : int direction:    Indicating north, south, east or west
  133.  *        int no_of_ofsts:Number of offsets
  134.  *        int *fe_address:Where the offset list is on the host
  135.  *
  136.  * Description: The list of offsets form a strip in the appropriate dimension
  137.  *        of a tiled virtual processor set, we want to shift them in
  138.  *        desired direction carrying the overflow between the tiles 
  139.  *        with toroidal wrap around.
  140.  *
  141.  * Result     : int:    FAIL/SUCCESS
  142.  *---------------------------------------------------------------------------*/
  143.  
  144. #ifdef __STDC__
  145.  
  146. visible int mp_xnet(int direction,int no_of_offsets,char *fe_address )
  147.  
  148. #else
  149.  
  150. visible int mp_xnet( direction, no_of_offsets, fe_address )
  151.  
  152. int direction;
  153. int no_of_offsets;
  154. char *fe_address;
  155.  
  156. #endif
  157.  
  158. {
  159.   natural first_ofst = 0;
  160.   int i, delta_x, delta_y;
  161.   natural *natural_scratch = (natural *) acu_scratch;
  162.   plural natural tmp, gws;
  163.   MP_PluralHeap MPPH_tmp;
  164.   int from_iproc, to_iproc;
  165.   object MPC;
  166.   plural int index;
  167.   
  168. DBG_CALL("mp_xnet");
  169. DBG_ARGS(fprintf(dbg,"direction=%d, no_of_ofsts=%d, fe_address=%x",direction,no_of_offsets,fe_address));
  170.  
  171.   if (copyIn(fe_address, acu_scratch, SCRATCH_MEMORY_SIZE) != 0) {
  172.  
  173.     mp_error = MP_COPY_IN_FAILED;
  174. DBG_FAIL(fprintf(dbg,"FAIL: Error paging in offset list"));      
  175.     return FAIL;
  176.   }
  177.  
  178.   PP_on_set() {
  179.  
  180.     /* do all the shifts */
  181.  
  182.     for (i=0; i< no_of_offsets; i++) {
  183.  
  184.       MPC = (object) natural_scratch[(i*2)];
  185.       MPP_2_MPPH( MPPH_tmp, natural_scratch[(i*2)+1]);
  186.       if (get(MPC, MPPH_tmp, direction) == FAIL) {
  187.  
  188. DBG_FAIL(fprintf(dbg,"FAIL: get failed for %dth plural", i));
  189.     return FAIL;
  190.       }
  191.     }
  192.       
  193.     /*  now handle edge condition thingies, we expect most of the contexts
  194.      *  to be the same so we set the activity to the edge of it to start off
  195.      */
  196.  
  197.    MPPH_tmp = &gws;
  198.  
  199.     MPC = (object) natural_scratch[0];
  200.     OM_with_context(MPC) {
  201.     
  202.       if (((direction==MP_NORTH) && OM_top_edge(MPC)) ||
  203.       ((direction==MP_SOUTH) && OM_bottom_edge(MPC)) ||
  204.       ((direction==MP_WEST) &&  OM_left_edge(MPC)) ||
  205.       ((direction==MP_EAST) && OM_right_edge(MPC))) {
  206.  
  207.     gws = plural_memory[natural_scratch[0+1]];
  208.     
  209.     for (i=1; i<no_of_offsets; i++) {
  210.     
  211.       if (MPC == (object) natural_scratch[2*i]) {
  212.         tmp = plural_memory[natural_scratch[(2*i)+1]];
  213.         plural_memory[natural_scratch[(2*i)+1]] = gws;
  214.         gws = tmp;
  215.         MPC =  (object) natural_scratch[2*i];
  216.       }
  217.       else { /* This is the last context */
  218.  
  219.         from_iproc = selectFirst();
  220.         scratch[0] = 1;
  221. DEBUG(DBG_PARG("iproc","%d ",iproc));
  222. DEBUG(DBG_PARG("scratch[0-3]","%08x ",*((plural int *) scratch)));
  223. DEBUG(DBG_PARG("type","%d ",OA_info(MPPH_tmp)));
  224.         encode(MPPH_tmp);
  225. DEBUG(DBG_PARG("scratch[0-3]","%08x ",*((plural int *) scratch)));
  226. DEBUG(DBG_PARG("scratch[4-7]","%08x ",*(((plural int *) scratch)+1)));
  227.         all {
  228.           PP_on_set() {
  229.           MPC =  (object) natural_scratch[2*i];
  230.           OM_with_context(MPC) {
  231.  
  232.         if (((direction==MP_NORTH) && OM_top_edge(MPC)) ||
  233.             ((direction==MP_SOUTH) && OM_bottom_edge(MPC)) ||
  234.             ((direction==MP_WEST) &&  OM_left_edge(MPC)) ||
  235.             ((direction==MP_EAST) && OM_right_edge(MPC))) {
  236.           
  237. DEBUG(DBG_PARG("iproc","%d ",iproc));
  238.  
  239.           to_iproc = selectFirst();
  240. DEBUG(fprintf(dbg,"from_iproc=%d, to_iproc=%d",from_iproc,to_iproc));
  241.                   delta_y = -((from_iproc/nxproc)-(to_iproc/nxproc));
  242.                   delta_x = (from_iproc-to_iproc)%nxproc;
  243. DEBUG(fprintf(dbg,"delta_x=%d, delta_y=%d",delta_x, delta_y));
  244.           ss_xfetch(delta_y,delta_x,scratch,scratch,
  245.                 SCRATCH_MEMORY_SIZE);
  246. DEBUG(DBG_PARG("scratch[0-3]","%08x ",*((plural int *) scratch)));
  247. DEBUG(DBG_PARG("scratch[4-7]","%08x ",*(((plural int *) scratch)+1)));
  248.           index = 1;
  249. DEBUG(DBG_PARG("gws","%d ",gws));
  250.           decode(MPPH_tmp,&index);
  251. DEBUG(DBG_PARG("gws","%d ",gws));
  252. DEBUG(DBG_PARG("type","%d ",OA_info(MPPH_tmp)));
  253. DEBUG(DBG_PARG("value","%d ",*(plural int *plural)OA_data(MPPH_tmp)));
  254.           tmp = plural_memory[natural_scratch[(2*i)+1]];
  255. DEBUG(DBG_PARG("tmp","%d ",tmp));
  256.           plural_memory[natural_scratch[(2*i)+1]] = gws;
  257.                   gws = tmp;
  258.           scratch[0] = 1;
  259.           encode(MPPH_tmp);
  260.           ss_xsend(delta_y,delta_x,scratch,scratch,
  261.                SCRATCH_MEMORY_SIZE);
  262.         }
  263.           }
  264.             }
  265.         }
  266. DEBUG(DBG_PARG("iproc","%d ",iproc));
  267.           index = 1;
  268.           decode(MPPH_tmp,&index);
  269.       }
  270.     }
  271.     plural_memory[natural_scratch[0+1]] = gws;
  272.       }
  273.     }
  274.   }
  275.   DBG_EXIT(fprintf(dbg,"SUCCESS"));
  276.   return SUCCESS;
  277. }
  278.  
  279.   
  280. /*----------------------------------------------------------------------------*
  281.  * Function   : edge
  282.  *
  283.  * Parameters : object MPC:    The MasPar context whose contexts stacks we
  284.  *                are going to munge.
  285.  *        int direction:    The edge we want active
  286.  *
  287.  * Description: Context stack modifier in the same way as the foc functions
  288.  *        (perhaps it should be in that module) so that the indicated
  289.  *        edge of the rectangular context is active
  290.  *
  291.  * Result     : int:    
  292.  *---------------------------------------------------------------------------*/
  293.  
  294. #ifdef __STDC__
  295.  
  296. visible int mp_edge( object MPC, int direction )
  297.  
  298. #else
  299.  
  300. visible int mp_edge( MPC, direction )
  301.  
  302. object MPC;
  303. int direction;
  304.  
  305. #endif
  306.  
  307. {
  308.   int result;
  309.   plural natural old_context;
  310.   plural natural *plural new_context;
  311.   MP_PluralHeap MPPH_context_stack;
  312. DBG_CALL("mp_edge");
  313. DBG_ARGS(fprintf(dbg,"MPC=%x, direction=%d",MPC,direction));
  314.  
  315.   OM_with_context(MPC) {
  316.  
  317.     MPP_2_MPPH(MPPH_context_stack, OA_offset(MPC));
  318.     old_context = * (plural natural *plural) OA_data(MPPH_context_stack);
  319.  
  320.     if (cons(MPPH_context_stack, MPPH_context_stack,
  321.          MPPH_context_stack)==FAIL) {
  322.  
  323. DBG_FAIL(fprintf(dbg,"FAIL: Unable to cons up context stack"));
  324.       return FAIL;
  325.     }
  326.  
  327.     new_context = (plural natural *plural) OA_data(MPPH_context_stack);
  328.     *new_context = NIL;
  329.     if (old_context != NIL) {
  330.  
  331.       if (((direction == MP_NORTH) && OM_top_edge(MPC)) ||
  332.       ((direction == MP_SOUTH) && OM_bottom_edge(MPC)) ||
  333.       ((direction == MP_EAST) && OM_right_edge(MPC)) ||
  334.       ((direction == MP_WEST) && OM_left_edge(MPC))) {
  335.  
  336.     *new_context = NOT_NIL;
  337.       }
  338.     }
  339.  
  340.     if(globalor(*new_context != NIL) == 0) result = MP_NONE_ACTIVE;
  341.     else result = MP_SOME_ACTIVE;
  342.   }
  343.  
  344. DBG_EXIT(fprintf(dbg,"SUCCESS: %d",result));
  345.   return result;
  346. }
  347.  
  348.       
  349.